public class SortingStack{
  public Stack<Integer> sortAscending( Stack<Integer> oStack) {
    //version 2 stacks.
     Stack<Integer> nStack = new Stack<Integer>();
     
  while(!oStack.isEmpty()){
    while(nStack.isEmpty || (oStack.peek() > nStack.peek())){
      nStack.push(oStack.pop());
    }
    int temp = oStack.pop();
    while(!nStack.isempty() && oStack.peek() < nStack.peek() ){
      oStack.push(nStack.pop());    
    }
    nStack.push(temp);
    }
      
    return nStack;
    }
}